package com.wen.service.impl;

import com.wen.entity.enums.PageSize;
import com.wen.entity.po.AppUser;
import com.wen.entity.query.AppUserQuery;
import com.wen.entity.query.SimplePage;
import com.wen.entity.vo.PaginationResultVO;
import com.wen.mappers.AppUserMapper;
import com.wen.service.AppUserService;
import com.wen.utils.StringTools;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;


/**
 *  业务接口实现
 */
@Service("appUserService")
public class AppUserServiceImpl implements AppUserService {

	@Resource
	private AppUserMapper<AppUser, AppUserQuery> appUserMapper;

	/**
	 * 根据条件查询列表
	 */
	@Override
	public List<AppUser> findListByParam(AppUserQuery param) {
		return this.appUserMapper.selectList(param);
	}

	/**
	 * 根据条件查询列表
	 */
	@Override
	public Integer findCountByParam(AppUserQuery param) {
		return this.appUserMapper.selectCount(param);
	}

	/**
	 * 分页查询方法
	 */
	@Override
	public PaginationResultVO<AppUser> findListByPage(AppUserQuery param) {
		int count = this.findCountByParam(param);
		int pageSize = param.getPageSize() == null ? PageSize.SIZE15.getSize() : param.getPageSize();

		SimplePage page = new SimplePage(param.getPageNo(), count, pageSize);
		param.setSimplePage(page);
		List<AppUser> list = this.findListByParam(param);
		PaginationResultVO<AppUser> result = new PaginationResultVO(count, page.getPageSize(), page.getPageNo(), page.getPageTotal(), list);
		return result;
	}
	@Override
	public List<AppUser> getListByPage(AppUserQuery param) {
		int pageSize = param.getPageSize() == null ? PageSize.SIZE15.getSize() : param.getPageSize();

		SimplePage page = new SimplePage(param.getPageNo(), pageSize);
		param.setSimplePage(page);
		List<AppUser> list = this.findListByParam(param);
		return list;
	}
	/**
	 * 新增
	 */
	@Override
	public Integer add(AppUser bean) {
		return this.appUserMapper.insert(bean);
	}

	/**
	 * 批量新增
	 */
	@Override
	public Integer addBatch(List<AppUser> listBean) {
		if (listBean == null || listBean.isEmpty()) {
			return 0;
		}
		return this.appUserMapper.insertBatch(listBean);
	}

	/**
	 * 批量新增或者修改
	 */
	@Override
	public Integer addOrUpdateBatch(List<AppUser> listBean) {
		if (listBean == null || listBean.isEmpty()) {
			return 0;
		}
		return this.appUserMapper.insertOrUpdateBatch(listBean);
	}

	/**
	 * 多条件更新
	 */
	@Override
	public Integer updateByParam(AppUser bean, AppUserQuery param) {
		StringTools.checkParam(param);
		return this.appUserMapper.updateByParam(bean, param);
	}

	/**
	 * 多条件删除
	 */
	@Override
	public Integer deleteByParam(AppUserQuery param) {
		StringTools.checkParam(param);
		return this.appUserMapper.deleteByParam(param);
	}

	/**
	 * 根据Id获取对象
	 */
	@Override
	public AppUser getAppUserById(Long id) {
		return this.appUserMapper.selectById(id);
	}

	/**
	 * 根据Id修改
	 */
	@Override
	public Integer updateAppUserById(AppUser bean, Long id) {
		return this.appUserMapper.updateById(bean, id);
	}

	/**
	 * 根据Id删除
	 */
	@Override
	public Integer deleteAppUserById(Long id) {
		return this.appUserMapper.deleteById(id);
	}

	@Override
	public Integer getTotalCount() {
		return appUserMapper.getTotalCount();
	}




}